Skip to content

[wrangler] Open Container shells without SSH keys - #17304

Open
gpanders wants to merge 1 commit into
mainfrom
ganders/wrangler-open-container-shells-without-ssh-keys
Open

gpanders wants to merge 1 commit into
mainfrom
ganders/wrangler-open-container-shells-without-ssh-keys

Conversation

@gpanders

@gpanders gpanders commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

wrangler containers ssh now uses the Containers shell WebSocket by default. It needs no authorized_keys and no local OpenSSH. It allocates a PTY when stdin and stdout are terminals. --tty and --no-tty override that.

The shared spinner now shows the cursor again when it stops without a message. Before, the cursor stayed hidden for the whole shell session.

Commands run directly, without a remote shell. Output stops when the local reader closes the pipe, with exit code 141 as with SIGPIPE. The "Authenticating" spinner only shows when stdout is a terminal, so it does not mix with redirected output. The hidden OpenSSH options select the OpenSSH connection, as --legacy-openssh does.

containers-shared/src/shell.ts implements the interface expected by the Containers shell "protocol".

We also add a --legacy-openssh flag which is marked deprecated to support the existing OpenSSH option so that users that currently rely on this can keep using it (for now this is the only way to use port forwarding). The legacy in the option name is intentional, it's meant to be a clear signal to users that this option shouldn't be used or depended on.

See CC-9581.



Devin Review

@changeset-bot

changeset-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 221504a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
wrangler Minor
@cloudflare/containers-shared Minor
@cloudflare/cli-shared-helpers Patch
@cloudflare/deploy-helpers Patch
@cloudflare/dev-helpers Patch
@cloudflare/autoconfig Patch
@cloudflare/remote-bindings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Nov 30, 2026
@workers-devprod
workers-devprod requested review from a team and jamesopstad and removed request for a team November 30, 2026 22:14
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/cloudchamber
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/containers-keyless-ssh.md: [@cloudflare/wrangler]
  • .changeset/spinner-show-cursor.md: [@cloudflare/wrangler]
  • packages/cli/tests/interactive.test.ts: [@cloudflare/wrangler]
  • packages/cli/interactive.ts: [@cloudflare/wrangler]
  • packages/containers-shared/src/shell.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/containers-shared/src/ssh.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/containers-shared/tests/ssh.test.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/wrangler/src/tests/containers/ssh.test.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/wrangler/src/containers/ssh.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]

Comment thread packages/containers-shared/src/ssh.ts Outdated
Comment on lines +144 to +146
const sshResponse = await promiseSpinner(mint(), {
message: "Authenticating",
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When stdin is a terminal but stdout is redirected, promiseSpinner() takes its noninteractive branch and writes Authenticating to stdout before the remote command output. This makes a command such as wrangler containers ssh <id> -- cat file >file produce a corrupted local file. Skip the spinner unless stdout is a terminal.

Suggested change
const sshResponse = await promiseSpinner(mint(), {
message: "Authenticating",
});
const sshResponse =
process.stdout.isTTY === true
? await promiseSpinner(mint(), { message: "Authenticating" })
: await mint();

@ask-bonk

ask-bonk Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds keyless container shell sessions with TTY handling and legacy OpenSSH fallback.

  1. P1: Piped shell command output is corrupted by the authentication spinner when stdin is a TTY and stdout is redirected. Posted 1 inline suggestion.

github run

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 221504a1.

This review, of 9707da80

💬 Approved with comments — One WARNING: ProxyCommand setups that pass a command after -- (for example -- %p) no longer get the SSH stdio proxy unless --legacy-openssh is added, and the changeset calls the auto-detection unchanged.

Findings: 1 warning (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #17304.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] ProxyCommand auto-detection no longer applies when a command follows `--` (for example `-- %p`) unless `--legacy-openssh` is set, which breaks existing setups. The changeset calls the auto-detection unchanged.
- **File:** packages/containers-shared/src/ssh.ts:467

📋 Code Quality: ⚠️ 1 warning

ProxyCommand auto-detection now depends on whether a command is given, which breaks existing -- <port> setups.

Recommendation: 📝 Minor Comments

  • [WARNING] ProxyCommand auto-detection no longer applies when a command follows -- (for example -- %p) unless --legacy-openssh is set, which breaks existing setups. The changeset calls the auto-detection unchanged. (packages/containers-shared/src/ssh.ts:467)
View full review

ProxyCommand auto-detection changes when a command follows -- (packages/containers-shared/src/ssh.ts:456-470)

On the base branch, shouldUseStdio returned true whenever stdin and stdout were both redirected and --tty was not set. Any trailing command was ignored. Now the redirected-stream case also needs legacyOpenssh === true || !command?.length. So an invocation like ProxyCommand wrangler containers ssh %h -- %p takes the new shell path and tries to run the port number as a command in the container, instead of proxying SSH traffic. The existing wrangler test that used containers ssh <id> -- 22 had to gain --legacy-openssh in this pull request to keep passing, which shows the old form used to work. .changeset/containers-keyless-ssh.md says "--stdio and the ProxyCommand auto-detection are unchanged". That holds only when no command is given.

Two ways to fix this: keep the old detection for redirected streams when no --tty/--no-tty is given, or state the break explicitly in the changeset (setups that use -- <port> must add --stdio or --legacy-openssh). Either way, a test without --legacy-openssh should pin down the intended behaviour.


✅ All other checks passed

🔒 Security: ✅ LGTM

The bearer token goes only to the URL the API returns, and the command is sent in the first WebSocket frame rather than in the URL. Malformed ACK and EXIT frames are handled safely, and the terminal is restored on every exit path. The OpenSSH code path now runs only behind --legacy-openssh.


📖 AGENTS.md: ✅ LGTM

No issues found.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The changeset statement that ProxyCommand auto-detection is unchanged is covered by the code quality finding on packages/containers-shared/src/ssh.ts:467.


Reviewed commit: 9707da80

Comment thread packages/containers-shared/src/ssh.ts Outdated
// An explicit --tty requests a terminal session, so it must not be
// mistaken for ProxyCommand usage when both streams are redirected.
(sshArgs.tty !== true &&
(sshArgs.legacyOpenssh === true || !sshArgs.command?.length) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ WARNING · Code Quality

ProxyCommand auto-detection no longer applies when a command follows -- (for example -- %p) unless --legacy-openssh is set, which breaks existing setups. The changeset calls the auto-detection unchanged.

On the base branch, redirected stdin and stdout always selected the stdio proxy, and a trailing command was ignored. With this condition, ProxyCommand wrangler containers ssh %h -- %p takes the new shell path and tries to run 22 in the container, so SSH stops connecting. The existing wrangler test for -- 22 had to add --legacy-openssh in this pull request to keep passing. Either keep the old detection when no --tty/--no-tty is given, or say in .changeset/containers-keyless-ssh.md that -- <port> ProxyCommand setups must now add --stdio or --legacy-openssh. The changeset currently calls the auto-detection "unchanged".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on purpose. wrangler containers ssh <id> -- <cmd> should run <cmd> even when stdin and stdout are pipes, for example cat f | wrangler containers ssh <id> -- sh -c 'cat > /tmp/f'. Before, proxy mode ignored everything after --, so -- %p never did anything, and the docs only show ProxyCommand="wrangler containers ssh %h". I updated the changeset to call out the change: a ProxyCommand that passes arguments after -- needs --stdio.

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@17304

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@17304

@cloudflare/cli-shared-helpers

npm i https://pkg.pr.new/@cloudflare/cli-shared-helpers@17304

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@17304

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@17304

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@17304

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@17304

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@17304

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@17304

miniflare

npm i https://pkg.pr.new/miniflare@17304

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@17304

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@17304

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@17304

@cloudflare/test-server

npm i https://pkg.pr.new/@cloudflare/test-server@17304

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@17304

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@17304

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@17304

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@17304

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@17304

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@17304

wrangler

npm i https://pkg.pr.new/wrangler@17304

commit: 221504a

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 7 potential issues.

Devin Review

Comment thread packages/containers-shared/src/ssh.ts Resolved
Comment thread packages/containers-shared/src/shell.ts Resolved
Comment thread packages/containers-shared/src/ssh.ts Resolved
Comment thread packages/containers-shared/src/ssh.ts Resolved
userAgent: string
): Promise<number> {
const { stdin, stdout, stderr } = process;
const command = sshArgs.command?.length ? sshArgs.command : undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Quoted remote commands change meaning

With -- 'pwd; whoami', runShell sends one executable name. The OpenSSH path sends a command string for the remote shell to interpret.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread packages/containers-shared/src/ssh.ts Resolved
Comment on lines +69 to +74
const ws = new WebSocket(url, ["cf-container-shell.v1"], {
headers: {
authorization: `Bearer ${mint.token}`,
"user-agent": userAgent,
},
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Deployed shell handshake remains unverified

The shell fixture checks the request against a local WebSocket server. It does not verify that a production token works at /shell with the new subprotocol.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this against production: shells, commands, exit codes, PTY, resize and Ctrl-C all work against the live /shell endpoint with cf-container-shell.v1.

wrangler containers ssh now uses the Containers shell WebSocket by
default. It needs no authorized_keys and no local OpenSSH. It allocates
a PTY when stdin and stdout are terminals. --tty and --no-tty override
that.

The shared spinner now shows the cursor again when it stops without a
message. Before, the cursor stayed hidden for the whole shell session.

Commands run directly, without a remote shell. Output stops when the
local reader closes the pipe, with exit code 141 as with SIGPIPE. The
"Authenticating" spinner only shows when stdout is a terminal, so it
does not mix with redirected output. The hidden OpenSSH options select
the OpenSSH connection, as --legacy-openssh does.

`containers-shared/src/shell.ts` implements the interface expected by
the Containers shell "protocol".

We also add a `--legacy-openssh` flag which is marked deprecated to
support the existing OpenSSH option so that users that currently rely on
this can keep using it (for now this is the only way to use port
forwarding). The `legacy` in the option name is intentional, it's meant
to be a clear signal to users that this option shouldn't be used or
depended on.
@gpanders
gpanders force-pushed the ganders/wrangler-open-container-shells-without-ssh-keys branch from 9707da8 to 221504a Compare November 30, 2026 22:58

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — The one earlier warning is resolved: the changeset now documents the change to ProxyCommand handling when a command follows --. No new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

  • The bearer token goes only to the URL the API returns.
  • The command is sent in the first WebSocket frame, not in the URL.
  • Malformed ACK and EXIT frames are handled safely.
  • The OpenSSH path is used only with --legacy-openssh or one of the OpenSSH options.

📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

The changeset now says that a command after -- runs in the Container even when both streams are redirected, and that ProxyCommand setups passing arguments after -- must add --stdio. This matches shouldUseStdio in packages/containers-shared/src/ssh.ts, and the tests cover it.

I found no new defects:

  • Raw mode, the listeners, stdin and the cursor are restored in finally.
  • EPIPE on stdout is handled.
  • The spinner change is covered by a test.

⚡ Performance: ✅ LGTM

Stdin backpressure and per-frame buffering are bounded, and listeners are cleaned up.


📝 Documentation: ✅ LGTM

The changesets match the behaviour of the code.


Reviewed commit: 221504a1

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

Devin Review


Pass `--legacy-openssh` to use the previous connection with OpenSSH and the Container's authorized keys. `--legacy-openssh` is deprecated and will be removed in a future release. The hidden OpenSSH options also select this connection.

OpenSSH `ProxyCommand` setups keep working for port forwarding, SFTP and IDE tools such as VS Code Remote-SSH. With `--stdio`, or when stdin and stdout are both redirected and no command is given, Wrangler proxies SSH traffic to the Container as before. A command after `--` now runs in the Container, even when both streams are redirected. A `ProxyCommand` that passes arguments after `--` must add `--stdio`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Redirected command docs omit OpenSSH exception

With both streams redirected, shouldUseStdio still selects proxy mode for -i or --legacy-openssh unless --tty is set. The changeset says a command after -- runs in the Container even with both streams redirected.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +529 to +534
const run = sshCommand({ id: "instance", command: ["yes"] }, "test-cli");
const { socket, output } = await connected;
const closed = once(socket, "close");
output(1, "y\n");
await expect(run).resolves.toBe(141);
await closed;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Broken pipe test omits remote exit

The test leaves exited pending until the write fails. In openShell, a remote exit can settle it before the pending write reports EPIPE.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants